import { ref } from 'vue'
import { activePreShareApi, activeShareApi } from '@/api/activity.js'
import { shareHomePageApi, shareMallPageApi } from '@/api/business.js'

export const useShare = () => {
	const showChoosePopup = ref(false)
	
	const preShareData = ref(null)
	const shareActiveData = ref(null)
	
	const getPreShare = (id) => {
		return activePreShareApi({
			id
		}).then(res => {
			preShareData.value = res
			showChoosePopup.value = res.popupState
			return res
		})
	}
	
	const getShareActivityData = async (activityId, extParams={}) => {
		showChoosePopup.value = false
		const res = await activeShareApi({
			id: activityId,
			...(extParams||{})
		})
		console.log('分享数据', res)
		shareActiveData.value = res
		return res
	}
	
	/**
	 * 分享策划人主页
	 */
	const shareHomePage = async (id) => {
		const res = await shareHomePageApi({ id })
		// console.log('商家主页分享', res)
		return res
	}
	
	/**
	 * 分享积分商城
	 */
	const shareMallPage = async (businessId) => {
		const res = await shareMallPageApi({ businessId })
		return res
	}
	
	return {
		getPreShare,
		getShareActivityData,
		preShareData,
		shareActiveData,
		shareHomePage,
		shareMallPage
	}
}
